package com.dongqi.sceneState.service.impl;

import com.dongqi.sceneState.dto.SceneStateDTO;
import com.dongqi.sceneState.dto.SceneTaskDTO;
import com.dongqi.sceneState.entity.SceneSituationEntity;
import com.dongqi.sceneState.entity.SceneTaskEntity;
import com.dongqi.sceneState.mapper.SceneSituationMapper;
import com.dongqi.sceneState.mapper.SceneTaskMapper;
import com.dongqi.sceneState.service.SceneStateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
@Transactional
public class ScenceStateServiceImpl implements SceneStateService {

    @Autowired
    private SceneSituationMapper sceneSituationMapper;

    @Autowired
    private SceneTaskMapper sceneTaskMapper;

    @Override
    public SceneStateDTO queryAll() {
        SceneStateDTO sceneStateDTO = new SceneStateDTO();
        //现场情况
        List<SceneSituationEntity> sceneSituationEntities = sceneSituationMapper.selectList(null);
        if (sceneSituationEntities.size() > 0) {
            SceneSituationEntity sceneSituationEntity = sceneSituationEntities.get(0);
            BeanUtils.copyProperties(sceneSituationEntity, sceneStateDTO);
        }
        //任务列表
        List<SceneTaskEntity> sceneTaskEntities = sceneTaskMapper.selectList(null);
        List<SceneTaskDTO> arrayList = new ArrayList<>();
        if (sceneSituationEntities.size() > 0) {
            for (SceneTaskEntity sceneTaskEntity : sceneTaskEntities) {
                SceneTaskDTO sceneTaskDTO = new SceneTaskDTO();
                BeanUtils.copyProperties(sceneTaskEntity, sceneTaskDTO);
                arrayList.add(sceneTaskDTO);
            }
        }
        sceneStateDTO.setSceneTaskDTOList(arrayList);
        return sceneStateDTO;
    }

}
